﻿using GalaSoft.MvvmLight;   //MVVM框架
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数据绑定
{
    
    //VIEWMODEL继承ViewModelBase
    class MModel :ViewModelBase
    {
        public MModel()
        {
            Counter = 100;

            facai = new RelayCommand(() => {
                Counter = 8888888;
            });

            Task.Run(
                async() =>
                {
                    await Task.Delay(2000);
                    Counter += 200;
                }
                );


        }


        private int counter;
        public int Counter
        {
   
            get { return counter; }
            set { 
                    counter = value;
                    //写上这句就自动实现MVVM数据通知
                    RaisePropertyChanged();  
                }
        }

        public RelayCommand facai { get; set; }
    }
}
